package com.neusoft.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;

/**
 * @Author: duan
 * @Date: Create in 16:54 2020/10/26
 */
public class StudentDaoImpl implements StudentDao {

    public StudentDaoImpl() {
        System.out.println("构造方法创建");
    }

    public void init() {
        System.out.println("init初始化");
    }

    public void destroyed() {
        System.out.println("destroyed被销毁了");
    }

    @Override
    public boolean save() throws Exception {
        System.out.println("调用save方法");
        //创建数据源
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        //设置数据库连接参数
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mall");
        dataSource.setUser("root");
        dataSource.setPassword("root");
        //获得连接对象
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        return false;
    }

    @Override
    public boolean update() {
        return false;
    }
}
